﻿@{
    ViewBag.Title = "添加新闻";
    Layout = "~/Views/Shared/_Main.cshtml";
}
<script src="/Scripts/ueditor1_4_3_2-utf8-net/utf8-net/ueditor.all.min.js"></script>
<form class="form-horizontal" action="TableNews" enctype="multipart/form-data" method="post" id="news">
    <div class="form-group">
        <label for="inputEmail3" class="col-sm-2 control-label">标题</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="Title" name="Title">
        </div>
    </div>
    <div class="form-group">
        <label for="inputPassword3" class="col-sm-2 control-label">副标题</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="Subtitle" name="Subtitle">
        </div>
    </div>
    @*<div class="form-group">
        <label for="inputPassword3" class="col-sm-2 control-label">所属栏目</label>
        <div class="col-sm-10">
            <select class="form-control" id="column" name="ColumnID"></select>
        </div>
    </div>*@
    <div>
        <input type="hidden" name="ColumnID" value="705BB527-E2D3-4730-96DD-6013026E7B54" />
    </div>
    <div class="form-group">
        <label for="inputPassword3" class="col-sm-2 control-label">封面</label>
        <div class="col-sm-10">
            <input type="file" class="form-control" id="CoverURL" name="Cover">
        </div>
    </div>
    <div class="form-group">
        <label for="inputPassword3" class="col-sm-2 control-label">视频</label>
        <div class="col-sm-10">
            <input type="file" class="form-control" id="VideoURL" name="Video">
        </div>
    </div>
    <div class="form-group">
        <label for="inputPassword3" class="col-sm-2 control-label">内容</label>
        <div class="col-sm-10">
            <!-- 加载编辑器的容器 -->
            <script id="container" name="content" type="text/plain" style="height:300px;">
            </script>
            <div class="hidden">
                <input type="hidden" id="ContentTxt" name="ContentTxt" />
                <input type="hidden" id="HTML" name="HTML" />
            </div>
        </div>
    </div>
    <input type="hidden" name="ID" />
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <a href="javascript:void(0)" class="btn btn-primary btn-lg active" role="button" id="save">保存</a>
        </div>
    </div>
</form>
<script id="tpl-row1" type="textml">
    {{each ApiParamObj as value i}}
    <option value="{{ value.ID }}">{{ value.Name }}</option>
    {{/each}}
</script>
<!-- 配置文件 -->
<script type="text/javascript" src="/Scripts/ueditor1_4_3_2-utf8-net/utf8-net/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="/Scripts/ueditor1_4_3_2-utf8-net/utf8-net/ueditor.all.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">

    var S = getQueryStringByName('S');
    if (S == 1) {
        if (confirm('添加成功，是否返回列表？')) {
            location.href = 'List';
        }
    }

    //$.ajax({
    //    url: '/api/CommonApi?API=Corey_GetColumns2',
    //    type: 'get',
    //    dataType: 'json',
    //    success: function (data) {
    //        if (data.Success) {
    //            if (data.ApiParamObj.length > 0) {
    //                $('#column').html(template('tpl-row1', data));
    //            }
    //        }
    //    }
    //});

    var toolbars = [
    [
        'bold', //加粗
        'italic', //斜体
        'underline', //下划线
        'subscript', //下标
        'selectall', //全选
        'horizontal', //分隔线
        'removeformat', //清除格式
        'cleardoc', //清空文档
        'fontfamily', //字体
        'fontsize', //字号
        'justifyleft', //居左对齐
        'justifyright', //居右对齐
        'justifycenter', //居中对齐
        'justifyjustify', //两端对齐
        'forecolor', //字体颜色
        'backcolor', //背景色
        'rowspacingtop', //段前距
        'rowspacingbottom', //段后距
        'imagecenter', //居中
        'lineheight', //行间距
        'insertimage' //多图上传

    ]
    ];

    var ue = UE.getEditor('container', { toolbars: toolbars });

    $('#save').click(function () {

        var fileFormat1 = '.jpg.jpeg.png';
        var fileFormat2 = '.mp4.mp3';

        var Title = $.trim($('#Title').val());
        var Subtitle = $.trim($('#Subtitle').val());
        var ColumnID = '705BB527-E2D3-4730-96DD-6013026E7B54';
        var ContentTxt = $.trim(ue.getContentTxt());
        var HTML = ue.getContent();
        var CoverURL = $('#CoverURL').val();
        var VideoURL = $('#VideoURL').val();


    //else if (ContentTxt == '') {
    //        alert('请输入内容！');
    //        return;
    //    } 

        if (Title == '') {
            alert('请输入标题！');
            return;
        } else if (Subtitle == '') {
            alert('请输入副标题！');
            return;
        } else if (CoverURL != '') {
            var fileName1 = CoverURL.substring(CoverURL.lastIndexOf('.'));
            if (fileFormat1.toLowerCase().indexOf(fileName1) < 0) {
                alert('请上传 JPG 或者 PNG 格式的图片！');
                return;
            }
        } else if (VideoURL != '') {
            var fileName2 = VideoURL.substring(VideoURL.lastIndexOf('.'));
            if (fileFormat2.toLowerCase().indexOf(fileName2) < 0) {
                alert('请上传 MP4 格式的视频！');
                return;
            }
        }

        $('#ContentTxt').val(ContentTxt);
        $('#HTML').val(HTML);

        $('#news').submit();

    });

    $('#news').onkeydown(function () {
        if (event.keyCode == 13) { return false; }
    });

</script>